<template> 
  <div class="app-container">
    <el-card class="filter-container" shadow="never">
      <div style="margin-top: 15px">
        <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
          <el-form-item label="推广员昵称：">
            <el-input v-model="listQuery.memberName" class="input-width" placeholder="请填写推广员昵称"></el-input>
          </el-form-item>
          <el-form-item label="推广员ID：">
            <el-input v-model="listQuery.memberId" class="input-width" placeholder="请填写推广员ID"></el-input>
          </el-form-item>
          <el-form-item label="提现账号：">
            <el-input v-model="listQuery.getMoneyAccount" class="input-width" placeholder="请填写提现账号"></el-input>
          </el-form-item>
          <el-form-item label="状态：">
            <el-select v-model="listQuery.state" class="input-width" placeholder="全部" clearable>
              <el-option v-for="item in states"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="提交时间：">
            <el-date-picker
              class="data-pick-style"
              v-model="listQuery.startDateTime"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择开始日期时间">
            </el-date-picker>
            -
            <el-date-picker
              class="data-pick-style"
              v-model="listQuery.endDateTime"
              type="datetime"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择结束日期时间">
            </el-date-picker>
          </el-form-item>
          <el-button
            class="search-Btn"
            type="primary"
            size="medium"
            icon="el-icon-search"
            @click="handleSearchList()">
            检索
          </el-button>
        </el-form>
      </div>
    </el-card>
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>数据列表</span>
    </el-card>
    <div class="table-container">
      <el-table ref="orderTable"
                :data="list"
                style="width: 100%;"
                @selection-change="handleSelectionChange"
                v-loading="listLoading" border>
        <el-table-column type="selection"  :selectable='isCheckboxTable' width="60" align="center"></el-table-column>
        <el-table-column label="推广员昵称" width="120" align="center">
          <template slot-scope="scope">{{scope.row.memberName}}</template>
        </el-table-column>
        <el-table-column label="推广员ID" align="center">
          <template slot-scope="scope">{{scope.row.memberId}}</template>
        </el-table-column>
        <el-table-column label="真实姓名" width="120" align="center">
          <template slot-scope="scope">{{scope.row.realName || '--'}}</template>
        </el-table-column>
        <el-table-column label="提现账号" width="120" align="center">
          <template slot-scope="scope">{{scope.row.mobilePhone}}</template>
        </el-table-column>
        <el-table-column label="提现金额"  align="center">
          <template slot-scope="scope">{{scope.row.money | formatMoney}}</template>
        </el-table-column>
        <el-table-column label="打款金额" align="center">
          <template slot-scope="scope">{{scope.row.money | formatMoney}}</template>
        </el-table-column>
        <el-table-column label="申请时间" align="center">
          <template slot-scope="scope">{{scope.row.createTime}}</template>
        </el-table-column>
        <el-table-column label="状态"  align="center">
          <template slot-scope="scope">{{scope.row.state | formatStatus}}</template>
        </el-table-column>
        <el-table-column label="备注"  align="center">
          <template slot-scope="scope">{{scope.row.remark || '--'}}</template>
        </el-table-column>
        <el-table-column label="操作"  width="200" align="center">
          <template slot-scope="scope" v-if="scope.row.state == 0">
            <el-button
              type="success"
              @click="passHandle(scope.row)">通过</el-button>
            <el-button
              type="danger"
              @click="noPassHandle(scope.row)">不通过</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="batch-operate-container">
      <el-select
        size="small"
        v-model="operateType" placeholder="批量操作">
        <el-option
          v-for="item in operateOptions"
          :key="item.value"
          :label="item.label"
          :value="item.value">
        </el-option>
      </el-select>
      <el-button
        style="margin-left: 20px"
        class="search-button"
        @click="handleBatchOperate()"
        type="primary"
        :disabled="!multipleSelection.length"
        size="small">
        确定
      </el-button>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize"
        :page-sizes="[5,10,15]"
        :total="total">
      </el-pagination>
    </div>
    <!--决绝原因的dialog-->
    <el-dialog title="拒绝原因" width="40%"  :visible.sync="dialogFormVisible">
      <el-form :model="dialogForm">
        <el-form-item label="原因:" label-width="120px">
          <el-input type="textarea" v-model="dialogForm.remark"  :autosize="{ minRows: 4, maxRows: 6}" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="isPassExamine(0)">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  import {formatDate, moneyFormat} from '@/utils/tools';
  import { Message } from 'element-ui'
  import requestApi from '@/api/index.js'

  const defaultListQuery = {
    pageNum: 1,
    pageSize: 10,
    memberName: '',
    memberId: '',
    getMoneyAccount: '',
    state: '',
    startDateTime: '',
    endDateTime: ''
  };
  export default {
    name: "account",
    data() {
      return {
        listQuery: Object.assign({}, defaultListQuery),
        listLoading: true,
        list: [],
        total: null,
        multipleSelection: [],
        ids: '', // 批量审核提款 id
        states: [
          {
            label: "提现中",
            value: 0
          },{
            label: "提现成功",
            value: 1
          },{
            label: "提现失败",
            value: 2
          },{
            label: "提现不通过",
            value: 3
          }
        ],
        operateType: null, // 批量操作确定按钮
        // 批量
        operateOptions: [
          {
            label: "批量通过",
            value: 1
          },
          {
            label: "批量不通过",
            value: 0
          }
        ],
        dialogFormVisible: false,
        dialogForm: {
          remark: ''
        },
      }
    },
    created() {
      this.getList();
    },
    filters: {
      formatCreateTime(time) {
        let date = new Date(time);
        return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
      },
      formatStatus(value) {
        if (value == 0) {
          return '提现中';
        } else if (value == 1) {
          return '提现成功';
        } else if (value == 2){
          return '提现失败';
        } else if (value == 3) {
          return '提现不通过';
        }
      },
      formatMoney(val) {
        return moneyFormat(val)
      }
    },
    methods: {
      isCheckboxTable(row) {
        if (row.state == 0) {
          return true;
        } else {
          return false;
        }
      },
      handleSearchList() {
        this.listQuery.pageNum = 1;
        this.getList();
      },
      handleSelectionChange(val){
        this.multipleSelection = val;
      },
      handleBatchOperate(){
        const idsTempArr = [];
        this.multipleSelection.forEach((val) => {
          idsTempArr.push(val.id);
        })
        console.log('批量提款id', this.operateType, idsTempArr.join(','));
        this.ids = idsTempArr.join(',');
        if (this.operateType == 1) {
          this.isPassExamine(this.operateType)
        } else {
          this.dialogForm.remark = '';
          this.dialogFormVisible = true;
        }
      },
      handleSizeChange(val){
        this.listQuery.pageNum = 1;
        this.listQuery.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val){
        this.listQuery.pageNum = val;
        this.getList();
      },
      getList() {
        this.listLoading = true;
        requestApi.getMoneyList(this.listQuery).then((res) => {
          this.listLoading = false;
          if (res.code == 0) {
            this.list = res.rows;
            this.total = res.total;
          } else {
            Message({
              message: res.message,
              type: 'error',
              duration: 3 * 1000
            })
          }
        }).catch(() => {
          Message({
            message: '服务器异常',
            type: 'error',
            duration: 3 * 1000
          })
        })
      },
      isPassExamine(type) {
        if (type == 0 && this.dialogForm.remark == '') {
          Message({
            message: '请填写原因',
            type: 'error',
            duration: 3 * 1000
          })
          return;
        }
        const param = {};
        param.getMoneyResult = type;
        param.getMoneyItemIds = this.ids;
        if (type == 0) param.nopassReason = this.dialogForm.remark;
        requestApi.getMoneyExamine(param).then((res) => {
          this.listLoading = false;
          if (res.code == 0) {
            Message({
              message: '审核成功',
              type: 'success',
              duration: 3 * 1000
            })
            // 刷新列表
            this.dialogFormVisible = false;
            this.dialogForm.remark = '';
            this.getList();
          } else {
            Message({
              message: res.message,
              type: 'error',
              duration: 3 * 1000
            })
          }
        }).catch(() => {
          Message({
            message: '服务器异常',
            type: 'error',
            duration: 3 * 1000
          })
        })
      },
      passHandle(row) {
        this.ids = row.id;
        this.isPassExamine(1);
      },
      noPassHandle(row) {
        this.ids = row.id;
        this.dialogForm.remark = '';
        this.dialogFormVisible = true;
      },
    }
  }
</script>
<style scoped>
  .input-width {
    width: 203px;
  }
  .search-Btn {
    margin-left:43px;
  }
  .data-pick-style {
    width: 200px;
  }
</style>


